package com.lucenten.collect.config.service.impl;

import javax.annotation.Resource;

import cn.quevo.common.entity.PageResult;

import cn.quevo.common.exception.CustomException;
import cn.quevo.common.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lucenten.collect.config.dao.SequenceIndexDao;
import com.lucenten.collect.config.entity.SequenceIndex;
import com.lucenten.collect.config.entity.query.SequenceIndexQuery;
import com.lucenten.collect.config.service.SequenceIndexService;

import java.util.Map;

/**
 * 序列索引 Service接口实现
 *
 * @author July july_sky@foxmail.com
 * @version 1.0
 * @date 2019/04/29 21:11:56
 * @Copyright 东方浩星（北京）传媒科技有限公司版权所有.All Rights Reserved.
 */
@Service("sequenceIndexService")
@Transactional(transactionManager="transactionManager",rollbackFor={Exception.class})
public class SequenceIndexServiceImpl implements SequenceIndexService {
    @Resource(name="sequenceIndexDao")
    private SequenceIndexDao sequenceIndexDao;


    @Override
    public SequenceIndex getNext(SequenceIndexQuery sequenceIndexQuery) {
        SequenceIndex sequenceIndex = this.sequenceIndexDao.getSequenceIndex(sequenceIndexQuery);
        if (sequenceIndex == null) {
            throw new CustomException(6100,"序列不存在");
        }
        if (this.sequenceIndexDao.update(sequenceIndex) <= 0) {
            this.getNext(sequenceIndexQuery);
        }
        return this.sequenceIndexDao.getSequenceIndex(sequenceIndexQuery);
    }
}
